import os
from datetime import timedelta


# 基本配置类
class BaseConfig(object):
    # 供session功能使用
    SECRET_KEY = os.getenv('SECRET_KEY', 'this is a secret_key')
    # session过期时间,通过session.permanent = True来使用
    PERMANENT_SESSION_LIFETIME = timedelta(days=7)
    # 首页端点名
    INDEX_ENDPOINT = 'index'

    # redis相关配置
    # redis配置1，使用0号库，为认证邮件相关业务提供支持
    REDIS_CONFIG_1 = {
        "host": "127.0.0.1",
        "port": 6379,
        "db": 0
    }


# 开发配置类
class DevConfig(BaseConfig):
    # 数据库相关设置
    SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URI')  # 数据库URI
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # flask-alchemy追踪对象的通知系统
    SQLALCHEMY_ECHO = False  # 是否显示sql语句

    # 发送邮件相关配置
    MAIL_SERVER = os.getenv('MAIL_SERVER', 'smtp.yeah.net')  # SMTP服务器
    MAIL_USE_SSL = True  # 使用SSL/TLS加密，对应端口465
    MAIL_PORT = 465
    MAIL_USERNAME = os.getenv('MAIL_USERNAME', 'chneyige@yeah.net')  # 邮箱
    MAIL_PASSWORD = os.getenv('MAIL_PASSWORD', '213xzhyaabc')  # 邮箱授权码
    MAIL_DEFAULT_SENDER = ('瑞典开心农场', MAIL_USERNAME)  # 默认发件人
    # 如果使用的邮箱支持TLS，则使用下面两项配置，并注释上面的"MAIL_USE_SSL"和"MAIL_PORT"
    # MAIL_USE_TLS = True  # 使用STARTTLS加密，对应端口587
    # MAIL_PORT = 587
    # 备用邮箱相关配置
    EXTRA_MAIL_CONFIGS = [
        {
            'MAIL_SERVER': 'smtp.yeah.net',
            'MAIL_USERNAME': 'guojiabaowen@yeah.net',
            'MAIL_PASSWORD': 'guojiabao321'
        },
        {
            'MAIL_SERVER': 'smtp.163.com',
            'MAIL_USERNAME': 'chenyigecyg3@163.com',
            'MAIL_PASSWORD': '213xzhyaabc'
        },
        {
            'MAIL_SERVER': 'smtp.sohu.com',
            'MAIL_USERNAME': 'chenyigecyg3@sohu.com',
            'MAIL_PASSWORD': '213xzhya'
        },
    ]

    # 七牛云相关配置
    QINIU_ACCESS_KEY = os.getenv('QINIU_ACCESS_KEY', 'NP1cit4pEKIkm3ndTid9uulki1nkZ3-PjmvTiyfF')  # Access key
    QINIU_SECRET_KEY = os.getenv('QINIU_SECRET_KEY', 'c32wXxhV-lCDRtvk_uY-ZGkvC1hJDkXSWLrgYlrJ')  # Secret key
    QINIU_BUCKET_NAME = os.getenv('QINIU_BUCKET_NAME', 'sweden-farm')  # 七牛云空间名

    DEFUALT_AVATAR_URL = 'http://q1998r88n.bkt.clouddn.com/FlPkS4f_nqrpuP-rIPme1L7M6e5w'  # 默认头像URL
    QINIU_URL = 'http://q1998r88n.bkt.clouddn.com/'  # 七牛云存储空间url


# 测试配置类
class TestConfig(BaseConfig):
    # 数据库相关设置
    SQLALCHEMY_DATABASE_URI = os.getenv('TEST_DATABASE_URI', 'mysql://root:123456@127.0.0.1:3306/blog_test')  # 数据库URI
    SQLALCHEMY_TRACK_MODIFICATIONS = False  # flask-alchemy追踪对象的通知系统
    # SQLALCHEMY_ECHO = True  # 调试时显示sql语句


# 生产配置类
class ProdConfig(BaseConfig):
    pass


# 配置名与配置类的映射关系
CONFIG_MAPPING = {
    'development': DevConfig,
    'testing': TestConfig,
    'product': ProdConfig
}

# 一些额外的配置项
